package com.example.wwj.controller;

import com.example.wwj.pojo.User;
import com.example.wwj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.wwj.vo.ResultVo;

import java.util.List;

@RestController
@RequestMapping("/user")
public class userController {
    @Autowired
    private UserService userService;

    /*
    * 查询所有的用户
    * */
    @GetMapping("/findAll")
    public List<User> index() {
        return userService.findAll();
    }


    /*
    * 保存新增用户
    * */
    @PostMapping("/save")
    public int save(@RequestBody User user) {
        return userService.save(user);
    }


    /*
    * 根据用户id删除用户休息
    * id:用户id
    * */
    @DeleteMapping("/delete/{id}")
    public int delete(@PathVariable Integer id) {
        return userService.deleteById(id);
    }

    /*
    * 根据用户id查询用户休息
    * id:用户id
    * */
    @GetMapping("/findById/{id}")
    public User findById(@PathVariable Integer id) {
        return userService.findById(id);
    }


    /*
    * 根据用户姓名查询用户休息
    * username:用户姓名
    * */
    @GetMapping("/findByUsername/{username}")
    public User findByUsername(@PathVariable String username) {
        return userService.findByUsername(username);
    }

//    @PostMapping("/regist")
//    public ResultVo regist(@RequestBody User user) {
//        System.out.println(user);
//        return userService.regist(user);
//    }

    /*
    * 登录
    * */
    @PostMapping("/login")
    public ResultVo login(@RequestBody User user) {
        System.out.println(user);
        return userService.login(user);
    }
}
